using System;
using System.Collections;
using System.Threading;
using System.Collections.Generic;
using UnityEngine;
using Cysharp.Threading.Tasks;
using DG.Tweening;

public partial class TillePanel : UIPanel
{
    private const string path = "Assets/Prefab/TillePanel.prefab";

    public TillePanel() : base(new UIType(path))
    {
        m_IsChildPanel = false;
    }

    public async override void OnEnter()
    {
        base.OnEnter();

        await AudioManager.Instance.Play(ClipKind.BackgoundMusic, AudioKind.Menu);

        m_LogoCanvasGroup.DOFade(1, 5);

        await UniTask.Delay(TimeSpan.FromSeconds(5));

        m_LogoRectTransform.DOLocalMoveY(349.26f, 3);

        await UniTask.Delay(TimeSpan.FromSeconds(3));

        m_FadeCanvasGroup.DOFade(0, 2);

        await UniTask.Delay(TimeSpan.FromSeconds(2));

        AddInputEventCallBack();
    }
    public override void OnPause()
    {
        base.OnPause();

        m_FadeCanvasGroup.blocksRaycasts = false;
    }
    public override void OnResume()
    {
        base.OnResume();

        m_FadeCanvasGroup.blocksRaycasts = true;
    }
    public async override UniTask OnStop(bool useAnim)
    {
        await base.OnStop(useAnim);

        RemoveInputEventCallBack();
    }
    private void AddInputEventCallBack()
    {
        m_FadeButton.onClick.AddListener(async() =>
        {
            await PanelManager.Instance.CreateUIPanel(new MenuPanel(), UIManager.Instance.transform);
        });
    }
    private void RemoveInputEventCallBack()
    {
        m_FadeButton.onClick.RemoveAllListeners();
    }
}
